package jwtx

import (
	"time"

	"github.com/golang-jwt/jwt/v5"
)

type CustomClaims[T any] struct {
	jwt.RegisteredClaims
	Data T `json:"data"`
}

// Validate can be used to execute additional application-specific claims
// validation.
func (m CustomClaims[T]) Validate() error {
	return nil
}

func NewCustomClaims[T any](dur time.Duration) CustomClaims[T] {
	now := time.Now()
	numericDate := jwt.NewNumericDate(now)
	registeredClaims := jwt.RegisteredClaims{
		Issuer:    "Issuer",
		Subject:   "Subject",
		Audience:  nil,
		ExpiresAt: jwt.NewNumericDate(now.Add(dur)),
		NotBefore: numericDate,
		IssuedAt:  numericDate,
		ID:        "",
	}
	return CustomClaims[T]{RegisteredClaims: registeredClaims}
}

// Ensure we implement [jwt.ClaimsValidator] at compile time so we know our custom Validate method is used.
var _ jwt.ClaimsValidator = (*CustomClaims[any])(nil)
